package impl;

import anaydis.sort.SorterType;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class InsertionSorter extends AbstractSorter {
    public InsertionSorter() {
        super(SorterType.INSERTION);
    }

    public <T> void sort(Comparator<T> comparator, List<T> list) {
       sort(comparator,list,0,list.size());
    }

    public <T> void sort(Comparator<T> comparator, List<T> list,int min, int max) {
        int tope = max;
        for (int i = min+1; i < tope; i++) {
            for (int j = i; j > min; j--) {
                if (greater(comparator, list, j-1 , j)) {
                    swap(list, j-1, j);
                }else{
                    break;
                }
            }
        }
    }
}
